//
//  JEHCarouselTableViewCell.m
//  SinaNews
//
//  Created by 蒋恩浩 on 15/12/3.
//  Copyright © 2015年 JEH. All rights reserved.
//

#import "JEHCarouselTableViewCell.h"

@interface JEHCarouselTableViewCell ()

@end

@implementation JEHCarouselTableViewCell

- (void)dealloc
{
    [_carousel release];
    [_titleArray release];
    [_picArray release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        if ([self respondsToSelector:@selector(layoutSubviews)]) {
            
            [self createView];
        }
    }
    return self;
}

- (void)setPicArray:(NSArray *)picArray {
    if (_picArray != picArray) {
        [_picArray release];
        _picArray = [picArray retain];
    }
}

- (void)setTitleArray:(NSArray *)titleArray {
    if (_titleArray != titleArray) {
        [_titleArray release];
        _titleArray = [titleArray retain];
    }
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    self.carousel.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [self.carousel setArray:self.picArray withTitArray:self.titleArray];
}

- (void)createView {
    
    self.carousel = [[Carousel alloc] initWithFrame:CGRectZero];
    [_carousel release];
    self.picArray = [NSMutableArray arrayWithCapacity:0];
    self.titleArray = [NSMutableArray arrayWithCapacity:0];
//    [self.carousel setTimer:2];
    [self addSubview:self.carousel];
    
#pragma mark - NightMode
    NSNotificationCenter *centers = [NSNotificationCenter defaultCenter];
    [centers addObserver:self selector:@selector(nightMode:) name:@"NightMode" object:nil];
}

- (void)nightMode:(NSNotification *)notification {
    
    if ([notification.object isEqualToString:@"YES"]) {
        
        self.carousel.backgroundColor = [UIColor darkGrayColor];
        _carousel.alpha = 0.7;
    } else {
        self.carousel.backgroundColor = [UIColor whiteColor];
        _carousel.alpha = 1;
    }
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
